<?php

class mentoria_Model extends CI_Model {
	
	public function __construct()
	{
		parent::__construct();
		$this->load->database();
	}
	
	public function get()
	{
		$this->db->order_by('date', 'desc');
		$query = $this->db->get('mentoria');
		return $query->result();
	}
	
	public function get_published()
	{
		$this->db->order_by('date', 'desc');
		$query = $this->db->get_where('mentoria', array('deleted'=>0));
		return $query->result();
	}
	
	public function get_featured()
	{
		$this->db->order_by('date', 'desc');
		$this->db->limit(4);
		$query = $this->db->get_where('mentoria', array('deleted'=>0));
		return $query->result();
	}
	
	public function get_id($id)
	{
		$query = $this->db->get_where('mentoria', array('id'=>$id));
		return $query->row();
	}
	
	public function get_id_published($id)
	{
		$query = $this->db->get_where('mentoria', array('id'=>$id, 'deleted'=>0));
		return $query->row();
	}
	
	public function get_all_inscritos()
	{
		$this->db->order_by('id_evento', 'desc');
		$query = $this->db->get('mentoria_inscritos');
		return $query->result();
	}
	
	public function get_inscritos($id_evento)
	{		
		$this->db->order_by('date', 'desc');
		$query = $this->db->get_where('mentoria_inscritos', array('id'=>$id_evento));
		return $query->result();
	}
	
	public function check_inscritos($id_evento, $dni)
	{
		$query = $this->db->get_where('mentoria_inscritos', array('id_evento'=>$id_evento, 'dni'=>$dni));
		return $query->result();
	}
	
	public function insert($input)
	{
		$query = $this->db->insert('mentoria', $input);		
		return $query;
	}
	
	public function insert_inscritos($input)
	{
		$id = $input['id_evento'];
		$query = $this->db->insert('mentoria_inscritos', $input);
		$query = $this->db->get_where('mentoria_inscritos', array('id_evento'=>$id));
		$filled = $query->num_rows();
		$query = $this->db->update('mentoria', array('filled'=>$filled), array('id'=>$id));
		return $query;
	}
	
	public function update($input, $id)
	{
		$query = $this->db->update('mentoria', $input, array('id'=>$id));
		return $query; 
	}
	
	public function delete($id)
	{
		$query = $this->db->delete('mentoria', array('id'=>$id));
		$query = $this->db->delete('mentoria_inscritos', array('id_evento'=>$id));
		return $query; 
	}
}

/* End of file novedades.php */
/* Location: ./application/models/novedades.php */